﻿<template>
  <a-modal
    title="新增发货作业"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
		<a-form :form="form">
        <a-form-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单据编号" v-decorator="['orderNo']" />
        </a-form-item>
        <a-form-item label="优先级" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入优先级" style="width: 100%" v-decorator="['priority']" />
        </a-form-item>
        <a-form-item label="发货仓库名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入发货仓库名称" v-decorator="['areaName']" />
        </a-form-item>
        <a-form-item label="交货日期" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择交货日期" v-decorator="['deliveryGoodsTime']" @change="onChangedeliveryGoodsTime"/>
        </a-form-item>
        <a-form-item label="计划号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入计划号" v-decorator="['planNo']" />
        </a-form-item>
        <a-form-item label="船号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入船号" v-decorator="['shipNo']" />
        </a-form-item>
        <a-form-item label="工程号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入工程号" v-decorator="['projectNo']" />
        </a-form-item>
        <a-form-item label="分配状态" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入分配状态" v-decorator="['assignmentStatus']" />
        </a-form-item>
        <a-form-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入客户" v-decorator="['custom']" />
        </a-form-item>
        <a-form-item label="电话联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入电话联系人" v-decorator="['phoneNumber']" />
        </a-form-item>
        <a-form-item label="收获地址" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入收获地址" v-decorator="['address']" />
        </a-form-item>
        <a-form-item label="运输公司" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入运输公司" v-decorator="['transportationCompany']" />
        </a-form-item>
        <a-form-item label="运输单号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入运输单号" v-decorator="['transportationOrderNo']" />
        </a-form-item>
        <a-form-item label="取消原因" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入取消原因" v-decorator="['reasonForCancellation']" />
        </a-form-item>
        <a-form-item label="整单收货" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入整单收货" v-decorator="['isFullOrder']" />
        </a-form-item>
        <a-form-item label="货主编号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入货主编号" v-decorator="['shipperOrder']" />
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入备注" v-decorator="['remarks']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    DispatchedWorkAdd
  } from '@/api/modular/main/DispatchedWorkManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        deliveryGoodsTimeDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {

        });
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.deliveryGoodsTime = this.deliveryGoodsTimeDateString
            DispatchedWorkAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangedeliveryGoodsTime(date, dateString) {
        this.deliveryGoodsTimeDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
